package com.atguigu.tingshu.album.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * ClassName: ThreadPoolConfig
 * Package: com.atguigu.tingshu.album.config
 * Description:线程池的配置
 */
@Configuration
public class ThreadPoolConfig {
    /**
     * 初始化线程池
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        //系统cpu核心数
        int processors = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(processors, processors * 2, 1, TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(100),
                Executors.defaultThreadFactory(),
                (r,executor)-> executor.submit(r)
        );
    }
}
